package com.ejuornal.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import com.ejuornal.bean.Board;
import com.ejuornal.dao.BoardDao;
import com.sun.crypto.provider.RSACipher;

@Component("boardDao")
public class BoardDaoImpl extends DaoSupport<Board> implements BoardDao {

	public void add(String sql, Object... objs) {
		super.add(sql, objs);
	}

	public void batchDelete(String sql, int... ids) {
		super.batchDelete(sql, ids);
	}

	public void update(String sql, Object... objs) {
		super.update(sql, objs);
	}

	public List<Board> findByPeriodicalId(int periodicalId) {
		String sql = "SELECT * FROM t_board WHERE periodicalId=?";
		List<Board> boardList = super.getJdbcTemplate().query(sql,
				new Object[] { periodicalId }, new RowMapper<Board>() {

					public Board mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						Board board = new Board();
						board.setBoardId(rs.getInt("boardId"));
						board.setName(rs.getString("name"));
						board.setPeriodicalId(rs.getInt("periodicalId"));
						
						return board;
					}
				});
		
		return boardList;
	}
}
